package com.pinyoumei.app.adapter;

import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.support.annotation.Nullable;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.widget.ImageView;
import android.widget.TextView;

import com.pinyoumei.app.R;
import com.pinyoumei.app.bean.SecondBean;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

import de.hdodenhof.circleimageview.CircleImageView;

/**
 * Created by Administrator on 2021-08-09.
 * --------- 日期 ------- 维护人 ------------ 变更内容 --------
 * 2021-08-09        Administrator             新增Person类
 * 2021-08-09        Administrator             增加sex属性
 */
public class SecondListAdapter extends BaseQuickAdapter<SecondBean.ResultBean.GoodsListBean, BaseViewHolder> {
    public SecondListAdapter(int layoutResId, @Nullable List<SecondBean.ResultBean.GoodsListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, SecondBean.ResultBean.GoodsListBean item) {

        ImageView iv_bg = helper.getView(R.id.iv_bg);
        Glide.with(mContext).load( item.getGoods_img()).into(iv_bg);


        TextView tv_title = helper.getView(R.id.tv_title);


        SpannableString msp =new SpannableString("  "+ item.getGoods_name());

        Drawable rightDrawable =mContext.getResources().

                getDrawable(R.mipmap.ic_item_second_bg);

        rightDrawable.setBounds(0,0,

                rightDrawable.getIntrinsicWidth(), rightDrawable.getIntrinsicHeight());

        msp.setSpan(new ImageSpan(rightDrawable),0,1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

        tv_title.setText(msp);


//        ivNumBg1 = findViewById(R.id.iv_num_bg_1);
//        ivNumBg2 = findViewById(R.id.iv_num_bg_2);
//        ivNumBg3 = findViewById(R.id.iv_num_bg_3);
//        ivNumBg4 = findViewById(R.id.iv_num_bg_4);
        CircleImageView ivNumBg1 = helper.getView(R.id.iv_num_bg_1);
        CircleImageView ivNumBg2 = helper.getView(R.id.iv_num_bg_2);
        CircleImageView ivNumBg3 = helper.getView(R.id.iv_num_bg_3);
        CircleImageView ivNumBg4 = helper.getView(R.id.iv_num_bg_4);

        List<String> user_head_imgs = item.getUser_head_imgs();
        if (user_head_imgs != null && user_head_imgs.size() > 0) {
            if (!TextUtils.isEmpty(user_head_imgs.get(0)) && user_head_imgs.size()>=1) {
                Glide.with(mContext).load(user_head_imgs.get(0)).into(ivNumBg1);
            }

            if (!TextUtils.isEmpty(user_head_imgs.get(1)) && user_head_imgs.size()>=2) {
                Glide.with(mContext).load(user_head_imgs.get(1)).into(ivNumBg2);
            }
            if (!TextUtils.isEmpty(user_head_imgs.get(2)) && user_head_imgs.size()>=3) {
                Glide.with(mContext).load(user_head_imgs.get(2)).into(ivNumBg3);
            }
            if (!TextUtils.isEmpty(user_head_imgs.get(3)) && user_head_imgs.size()>=4) {
                Glide.with(mContext).load(user_head_imgs.get(3)).into(ivNumBg4);
            }
        }



        helper.setText(R.id.tv_group_buying_num,"等" + item.getGroup_buying_num()+"人正在开团");

        TextView tv_market_price = helper.getView(R.id.tv_market_price);
        tv_market_price.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG|Paint.ANTI_ALIAS_FLAG); //中划线
        tv_market_price.setText("市场价：¥" + item.getMarket_price());

        helper.setText(R.id.tv_pt_price,"开心团劵：" +item.getPt_price());
    }




}
